package com.suep.business.mapper;

import com.suep.business.domain.StoreReview;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface StoreReviewMapper {

    // 主键精确查询
    @Select("SELECT reviewId, storeId, userId, rating, comment, reviewTime FROM store_review WHERE reviewId = #{reviewId}")
    StoreReview selectStoreReviewById(@Param("reviewId") Integer reviewId);

    // 按storeId外键查询
    @Select("SELECT reviewId, storeId, userId, rating, comment, reviewTime FROM store_review WHERE storeId = #{storeId}")
    List<StoreReview> selectStoreReviewByStoreId(@Param("storeId") Integer storeId);

    // 按userId外键查询
    @Select("SELECT reviewId, storeId, userId, rating, comment, reviewTime FROM store_review WHERE userId = #{userId}")
    List<StoreReview> selectStoreReviewByUserId(@Param("userId") Integer userId);

    // 主键精确删除
    @Delete("DELETE FROM store_review WHERE reviewId = #{reviewId}")
    Integer deleteStoreReviewById(@Param("reviewId") Integer reviewId);

    // 插入
    @Insert("INSERT INTO store_review (storeId, userId, rating, comment, reviewTime) VALUES " +
            "(#{storeId}, #{userId}, #{rating}, #{comment}, #{reviewTime, typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler})")
    Integer insertStoreReview(StoreReview storeReview);

    // 更新
    @Update("UPDATE store_review SET storeId = #{storeId}, userId = #{userId}, rating = #{rating}, comment = #{comment}, " +
            "reviewTime = #{reviewTime, typeHandler=org.apache.ibatis.type.LocalDateTimeTypeHandler} WHERE reviewId = #{reviewId}")
    Integer updateStoreReviewById(StoreReview storeReview);
}